package com.workshop.web;


import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.workshop.entity.UUser;
import com.workshop.service.IAArticleService;
import com.workshop.utils.check.CheckUtil;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengluqiang
 * @since 2019-04-13
 */
@RestController
@RequestMapping("/aArticle")
public class AArticleController {

    @Resource
    private IAArticleService articleService;

    /**
     * 所有活动列表
     * @author chenluqiang
     * @date 2019/4/13
     * @param [pageStart, pageTotal, type]
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws Exception 
     */
    @PostMapping("/list")
    public Map<String,Object> list(HttpServletRequest request,Long pageStart, Long pageTotal, Integer type) throws Exception{
        return articleService.allList(request,pageStart,pageTotal,type);
    }
    /**
     * 活动详情
     * @author chenluqiang
     * @date 2019/4/14
     * @param [artId]
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws Exception 
     */
    @PostMapping("/detail")
    public Map<String,Object> detail(HttpServletRequest request,String artId) throws Exception{
    	UUser user =(UUser) CheckUtil.checkOline(request);
        return articleService.detail(artId,user);
    }

    @PostMapping("/add")
    public Map<String,Object> add(HttpServletRequest request,String artJson) throws Exception{
    	CheckUtil.checkOline(request);
        return articleService.add(artJson);
    }
    @PostMapping("/search")
    public Map<String,Object> search(HttpServletRequest request,String keyword,Long pageStart, Long pageTotal)throws Exception{
    	CheckUtil.checkOline(request);
        return articleService.search(keyword,pageStart,pageTotal);
    }

    /**
     * 后台 所有活动列表
     * @author chenluqiang
     * @date 2019/4/13
     * @return java.util.Map<java.lang.String,java.lang.Object>
     * @throws Exception 
     */
    @PostMapping("/adminList")
    public Map<String,Object> adminList(HttpServletRequest request,Long pageStart, Long pageTotal) throws Exception{
    	CheckUtil.checkOline(request);
        return articleService.adminList(pageStart,pageTotal);
    }
    @PostMapping("/pass")
    public Map<String,Object> pass(HttpServletRequest request,String artId,Integer status) throws Exception {
        CheckUtil.checkOline(request);
        return articleService.pass(artId,status);
    }

    @PostMapping("/join")
    public Map<String,Object> join(HttpServletRequest request,String artId) throws Exception {
        UUser user = (UUser) CheckUtil.checkOline(request);
        return articleService.join(artId,user);
    }
}

